//
//  SendViewController.m
//  momo
//
//  Created by HappyMilk 02 on 2017/5/2.
//  Copyright © 2017年 tomi. All rights reserved.
//

#import "SendViewController.h"
#import "MessageModel.h"
#import "LoginHeader.h"
#import "evelModel.h"

@interface SendViewController ()

@property (weak, nonatomic) IBOutlet UITextField *tv_contents;

@end

@implementation SendViewController

- (IBAction)popvc:(UIButton *)sender {
    if (_is_reply) {
        [self dismissViewControllerAnimated:YES completion:nil];
        return;
    }
    [self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)sendMsg:(id)sender {
    if (_is_reply) {
        
        if (self.tv_contents.text.length>0) {
            SHOW_HUD(nil);
            evelModel *model = [evelModel object];
            model.msg_id = _msg_id;
            model.ev_contents = self.tv_contents.text;
            model.ev_name = _user_name;
            model.msg_user_id = _msg_user_id;
            model.user_id = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_id"];
            [model saveInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {
                HIDE_HUD;
                [self dismissViewControllerAnimated:YES completion:nil];
            }];
        }else{
            HIDE_HUD;
            SHOW_HUD_MESSAGE(@"Please enter message");
        }
    }else{
        
        if (self.tv_contents.text.length>0) {
            SHOW_HUD(nil);
            MessageModel *model = [MessageModel object];
            model.user_id = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_id"];
            model.message = self.tv_contents.text;
            [model saveInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {
                HIDE_HUD;
                [self.navigationController popViewControllerAnimated:YES];
            }];
        }else{
            HIDE_HUD;
            SHOW_HUD_MESSAGE(@"Please enter message");
        }
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [MessageModel registerSubclass];
    [evelModel registerSubclass];
    // Do any additional setup after loading the view.
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
